package com.hmall.search.web;

import com.hmall.feign.domain.dto.PageDTO;
import com.hmall.search.domain.po.ItemDoc;
import com.hmall.search.domain.query.ItemPageQuery;
import com.hmall.search.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
@Slf4j
public class SearchController {
    @Autowired
    SearchService searchService;

    @GetMapping("/suggestion")
    public List<String> suggestion(String key){
        log.info("自动补全的词条:{}",key);
        return searchService.suggestion(key);
    }

    @PostMapping("/filters")
    public Map<String,List<String>> filters(@RequestBody ItemPageQuery itemPageQuery){
        log.info("过滤项聚合:{}",itemPageQuery);
        return searchService.filters(itemPageQuery);
    }

    @PostMapping("/list")
    public PageDTO<ItemDoc> search(@RequestBody ItemPageQuery itemPageQuery){
        log.info("基本搜索功能:{}",itemPageQuery);
        return searchService.search(itemPageQuery);
    }

}
